var o = function (o) {
  return o && o.__esModule ? o : {
    default: o
  };
}(require("../../../../utils/toot.js"));
var bmap = require('../../../../utils/bmap-wx.min.js');
var app = getApp();
var tcity = require("../../../../utils/citys.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keshi_yiji_dex:0,
    keshi_erji_dex:0,
    isLoading: !0,
    provinces: [], //省份
    provincesdex: 0,
    citys: [], //城市
    citysdex: 0,
    tablist1: ["全部地区", "所属级别"],
    //星期
    zhic: 0,
    page: 0,
    pagback: 3,
    weekdex: 0,
    pinyin: "",
    ismore: true,
    weeks: "",
    itemList: [],
    list: [],
    week: "",
    date: "",
    hid: "",
    keshi_name:"科室",
    long: "", //远程挂号
    inquiry: 0, //0 图文  1 视频   2 电话   3 开药  8 手术
    needFix: false,
    bannerHeight: 0,
    searchlist: ["列表一", "列表二", "列表三", "列表四", "列表五", "列表六"],
    searchCont: "",
    openmore: false,
    tabdex: "",
    popshow: false,
    zongheList: [{
        items: "综合排序",
        checked: false
      },
      {
        items: "回答次数",
        checked: false
      },
      {
        items: "星级评分",
        checked: false
      },
      {
        items: "响应时间",
        checked: false
      },

    ],
    typeList: [{
        items: "图文问诊",
        checked: false
      },
      {
        items: "视频问诊",
        checked: false
      },
      {
        items: "电话问诊",
        checked: false
      },
      {
        items: "开药问诊",
        checked: false
      },
      {
        items: "手术快约",
        checked: false
      },
    ],
    city: "",
    shaixuanList: [{
        items: "价格区间",
      },
      {
        items: "医生职称",
      },
    ],
    jiage: [],
    yisheng: [{
        items: "主治医生",
        checked: false
      },
      {
        items: "主治医生2",
        checked: false
      }
    ],
    shequlist: [],
    shequdex: 0,
    typs: "",
    dex1: 0
  },
  // 选择一级科室
  keshi_yiji:function(e){
    console.log(e)
    var dex=e.currentTarget.dataset.dex;
    this.setData({
      keshi_yiji_dex:dex,
      keshi_one:e.currentTarget.dataset.id
    })
    this.getKeshi_two();
  },

  // 选择二级科室
  keshi_erji:function(e){
    console.log(e)
    var dex=e.currentTarget.dataset.dex;
    this.setData({
      keshi_erji_dex:dex,
      parentid:e.currentTarget.dataset.id,
      page:0,
      keshi_name:e.currentTarget.dataset.name,
      list:[]
    })
    this.hidepop()
    this.getAlldoclist();
  },


  //选择日期
  weekitem(e) {
    this.setData({
      weekdex: e.currentTarget.dataset.dex,
      date: e.currentTarget.dataset.data,
      week: e.currentTarget.dataset.week,
      weeks: e.currentTarget.dataset.weeks,
    })
    var weeks = e.currentTarget.dataset.weeks;
    var page = 0;
    this.setData({
      list: [],
      itemList: [],
      weeks: weeks,
      page: 0
    })
    this.getksbiaoqian(page, weeks)
  },
  // 筛选
  typesclick(e) {
    let datas = this.data;
    let i = e.currentTarget.dataset.index
    let dex = e.currentTarget.dataset.dex
    datas.ktypes.map(function (item) {
      item.checked = false
    })
    datas.ktypes[dex].checked = true
    console.log( datas.ktypes)
    this.setData({
      ktypes: datas.ktypes,
      ktypesText: datas.ktypes[dex].titles,
      pinyin:e.currentTarget.dataset.server_key
    })
  },
  typesclick1(e) {
    let datas = this.data;
    var that = this
    let i = e.currentTarget.dataset.index
    let dex = e.currentTarget.dataset.dex
    var section2 = that.data.section2
    datas.section2.map(function (item) {
      item.checked = false
    })
    datas.section2[dex].checked = true
    this.setData({
      section2: datas.section2,
      yishengText: datas.section2[dex].job_name
    })
  },
  // 重置
  resultclick() {
    let datas = this.data.shaixuanList;
    for (let i = 0; i < datas.length; i++) {
      let items = datas[i].section;
      for (let j = 0; j < items.length; j++) {
        items[j].checked = false
      }
    }
    this.setData({
      shaixuanList: datas
    })
  },
  // 完成
  submitclick() {
    var that = this
    var id = that.data.id
    var dex = that.data.dex
    var biaoqian = that.data.biaoqian
    var money = that.data.jiageText
    var zhic = that.data.yishengText
    var server_key = that.data.pinyin
    var hid = that.data.hid;
    that.setData({
      page: 0,
      pinyin: server_key,
      dex1: dex,
      popshow: false,
      tabdex: "",
      biaoqian: biaoqian,
      list: [],
      hid: hid,
      zhic: zhic
    })
    that.getAlldoclist(biaoqian)
  },
  // 社区选择
  shequclick(e) {
    var that = this
    var biaoqian = e.currentTarget.dataset.biaoqian
    var id = that.data.id
    var server_key = that.data.pinyin
    this.setData({
      shequdex: e.currentTarget.dataset.dex,
      page: 0,
      list: []
    })
    that.getAlldoclist(biaoqian)
  },
  getSearch: function (e) {
    var list = this.data.list
    var arr = []
    for (var i = 0; i < list.length; i++) {
      if (list[i].z_name.indexOf(e.detail.value) != -1) {
        arr.push(list[i])
      }
    }
    this.setData({
      searchCont: e.detail.value,
      searchArr: arr
    })
  },
  // 隐藏弹框
  hidepop() {
    this.setData({
      popshow: false,
      tabdex: ""
    })
  },
  // tab切换
  tabbtn(e) {
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex: "",
      })
    } else {
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex,

      })
    }
  },
  // 综合排序tab选项
  itemchecked(e) {
    var that = this
    let text = e.currentTarget.dataset.text
    var dex = e.currentTarget.dataset.dex
    var id = that.data.id
    var biaoqian = that.data.biaoqian
    this.setData({
      popshow: false,
      tabdex: "",
      zongheText: text,
      list: [],
      dex1: dex,
      page: 0
    })
    that.getAlldoclist(biaoqian)
  },
  // 类型tab选项
  itemchecked1(e) {
    var that = this
    var id = that.data.id
    var dex1 = that.data.dex1 //总和排序
    var server_key = e.currentTarget.dataset.server_key //服务类型
    var text = e.currentTarget.dataset.text
    var biaoqian = that.data.biaoqian
    that.setData({
      popshow: false,
      typeText: text,
      tabdex: "",
      tit: text,
      dex1: dex1,
      list: [],
      page: 0
    })
    that.getAlldoclist(biaoqian)
  },
  // 展开收起
  openmore() {
    this.setData({
      openmore: !this.data.openmore
    })
  },
  //解读报告
  readyreport() {
    if (this.data.inquiry == 5) {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?inquiry=5',
      })
      return false
    }
    if (this.data.inquiry == 6) {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=6',
      })
      return false
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this
    var bgc = wx.getStorageSync('color')
    var id = options.id
    var hid = options.hid;
    var addressname = app.globalData.addressname;
    var come = options.come;
    
    console.log(addressname)
    that.setData({
      addressname: addressname,
      come:come
    })
    //查询精选标签
    if (options.tid) {
      var tid = options.tid; //体检报告
      that.setData({
        tid: tid
      })
    }
    if (hid != undefined && hid != 'undefined') {
      that.setData({
        hid: hid
      })
    }
    if (options.ser_key && options.ser_key !== 'undefined') {
      var pinyin = options.ser_key
      that.setData({
        pinyin: pinyin
      })
    }

    that.getServer_name();
    var typs = options.typs;
    if (typs != undefined) {
      that.setData({
        typs: typs
      })
    }
    var tit = options.tit
    if (options.conets && options.conets !== 'undefined') {
      var conets = JSON.parse(options.conets)
      that.setData({
        conets: conets,
      })
    }
    var j_id = options.j_id
    that.setData({
      id: id,
      parentid:id,
      tit: tit,
      j_id: j_id,

    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      bgc:bgc
    })
    // wx.setNavigationBarTitle({
    //   title: options.tit,
    // })
    if (options.long) {
      console.log('2')
      this.setData({
        long: options.long
      })
      if (options.long == 'shoushu') {
        wx.setNavigationBarTitle({
          title: '手术快约',
        })
        let tablist = this.data.tablist
        tablist[1].types = '手术快约'
        tablist[1].list.map((item) => {
          if (item.items == '手术快约') {
            item.checked = true
          }
        })
        this.setData({
          tablist,
          inquiry: 8
        })
      }
    }
    app.util.request({
      url: "entry/wxapp/index.serverpxlist",
      success: function (resing) {
        console.log(resing)
        that.setData({
          ktypes: resing.data
        })
      }
    })
    if (options.ser_key == 'yuanchengguahao') {
      that.getSeven();
    } else {
      that.getAlldoczhicheng()

      that.getksbiaoqian()
    }
    that.getHotcity();
    that.getKeshi_one();
  },
  getKeshi_one:function(){
    var that = this;
    app.util.request({
      url:"entry/wxapp/index.address",
      data:{
        op:"keshi"
      },
      success:function(res){
        that.setData({
          one_arr:res.data,
          keshi_one:res.data[0].id
        })
        that.getKeshi_two();
      }
    })
  },
  getKeshi_two:function(res)
  {
    var that = this;
    app.util.request({
      'url':"entry/wxapp/index.parentclass",
      data:{
        id:that.data.keshi_one
      },
      success:function(res)
      {
        that.setData({
          two_list:res.data,
          // parentid:res.data[0].id,
          // keshi_name:res.data[0].name
        })
      }
    })
  },
  getHotcity: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.hot_address",
      success: function (res) {
        var citys = [];
        for (var i = 0; i < res.data.length; i++) {
          citys.push(res.data[i].name)
        }
        tcity.init(that);
        var cityData = that.data.cityData;
        const provinces = [];
        provinces.push("热门城市");
        for (let i = 0; i < cityData.length; i++) {
          provinces.push(cityData[i].name);
        }

        that.setData({
          provinces,
          citys,
        })
      }
    })
  },
  //城市
  cityitem(e) {
    var val = e.currentTarget.dataset.dex
    var name = e.currentTarget.dataset.name
    let tablist1 = this.data.tablist1
    var biaoqian = this.data.biaoqian;
    tablist1[0] = name
    this.setData({
      tablist1,
      citysdex: val,
      popshow: false,
      tabdex: "",
      page: 0,
      hospitallm: [],
      city: name,
      page: 0,
      list: []
    })
    this.getAlldoclist(biaoqian)
  },
  //选择省份
  provinceitem(e) {
    var val = e.currentTarget.dataset.dex
    var t = this.data.provincesdex;
    var cityData = this.data.cityData;
    if (val != t) {
      if (val > 0) {
        let ci = val - 1
        let citys = [];
        for (let i = 0; i < cityData[ci].sub.length; i++) {
          citys.push(cityData[ci].sub[i].name)
        }
        this.setData({
          citys,
          provincesdex: val
        })
      } else if (val == 0) {
        let citys = ["全国", "北京", "上海", "广州", "杭州", "西安", "武汉"];
        this.setData({
          citys,
          provincesdex: val
        })
      }
    }
  },
  getSeven: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.seven",
      success: function (res) {
        that.setData({
          seven: res.data,
          week: res.data[0].week,
          date: res.data[0].date,
          weeks: res.data[0].weeks
        })
        that.getksbiaoqian()
      }
    })
  },
  getServer_name: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.server_name",
      data: {
        key_words: that.data.pinyin
      },
      success: function (res) {
        console.log(res.data.titles);
        that.setData({
          tit: res.data.titles,
          typeText: res.data.titles
        })
      }
    })
  },
  navigator(e) {
    var that = this
    var zid = e.currentTarget.dataset.zid
    var server = e.currentTarget.dataset.server
    var pinyin = that.data.pinyin
    var money = e.currentTarget.dataset.money
    var typs = that.data.typs
    var conets = JSON.stringify(that.data.conets)
    var tkid = app.globalData.tkid
    console.log(tkid)
    app.util.request({
      'url': 'entry/wxapp/index.iftuoke',
      data: {
        openid: wx.getStorageSync('openid')
      },
      success: function (res) {
        console.log(res)
        if (tkid == 0) {
          //我不是推客
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getdocerweima',
            data: {
              zid: zid,
            },
            success: function (res) {
              console.log(res)
            }
          })
        } else {
          //我是推客
          var id = res.data.id
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.tuikedocerweima',
            data: {
              zid: zid,
              tkid: tkid,
              openid: wx.getStorageSync('openid')
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      }
    })

    if (pinyin == "yuanchengkaifang") {
      //跳转支付
      var j_id = that.data.j_id
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/huanzhezhifu/huanzhezhifu?key_words=' + pinyin + '&conets=' + conets + '&zid=' + zid + '&j_id=' + j_id + '&typs=' + typs + '&money=' + money + '&arr=undefined',
      })
      return false;
    }
    if (pinyin == "") {
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid=' + zid + '&money=' + money,
      })
      return false;
    }
    if (pinyin == "shipinwenzhen" || pinyin == "tuwenwenzhen" || pinyin == "dianhuajizhen" || pinyin == "sirenyisheng") {
      let inquiry = this.data.inquiry
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?inquiry=' + inquiry + '&zid=' + zid + '&server=' + server + '&money=' + money,
      })
      return false;
    }
    if (pinyin == "shoushukuaiyue") {
      let inquiry = this.data.inquiry
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?inquiry=' + inquiry + '&zid=' + zid + '&server=' + server + '&typs=' + typs + '&money=' + money
      })
      return false;
    }
    if (pinyin == 'tijianjiedu') {
      let inquiry = this.data.inquiry
      if (this.data.tid) {
        wx.navigateTo({
          url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?inquiry=' + inquiry + '&zid=' + zid + '&server=' + server + '&money=' + money + '&tid=' + this.data.tid
        })
      } else {
        wx.navigateTo({
          url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?inquiry=' + inquiry + '&zid=' + zid + '&server=' + server + '&money=' + money
        })
      }

      return false;
    }
    if (pinyin == 'yuanchengguahao') {
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/doctor_detail/doctor_detail?inquiry=1&zid=' + zid + '&server=' + server + '&money=' + money
      })
      return false;
    }
    // else if (this.data.long == 'shoushu') {
    //   wx.navigateTo({
    //     url: '/hyb_yl/zhuanjiasubpages/pages/orderedtime/orderedtime?inquiry=' + this.data.inquiry + '&zid=' + zid + '&server=' + server
    //   })
    // } else {
    //   let inquiry = this.data.inquiry
    //   wx.navigateTo({
    //     url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?inquiry=' + inquiry + '&zid=' + zid + '&server=' + server
    //   })
    // }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getAlldoc()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getAlldoc() {
    var that = this
    var id = that.data.id
    var pinyin = that.data.pinyin //服务id
    console.log(pinyin)
    // if (pinyin !== "") {
    //   app.util.request({
    //     'url': 'entry/wxapp/zhuanjia.listall',
    //     data: {
    //       id: id,
    //       ser_key: pinyin
    //     },
    //     success: function (res) {
    //       console.log(res)
    //       that.setData({
    //         list: res.data
    //       })
    //     }
    //   })
    // }

  },
  //查询可是分类标签
  getksbiaoqian() {

    var that = this
    var id = that.data.id
    var server_key = that.data.pinyin
    app.util.request({
      'url': 'entry/wxapp/index.getksbiaoqian',
      data: {
        id: id,
      },
      success: function (res) {
        console.log(res)
        var biaoqian = res.data[0]
        that.getAlldoclist(biaoqian)
        that.setData({
          shequlist: res.data,
          biaoqian: biaoqian
        })
        //console.log(that.data.shequlist);
      }
    })
  },
  getAlldoclist() {
    var that = this
    var server_key = that.data.pinyin
    var week = that.data.weeks
    var dex1 = that.data.dex1
    var zhic = that.data.zhic

    if (that.data.city == '') {
      var city = that.data.addressname
    } else {
      var city = that.data.city
    }
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getlistall',
      data: {
        id: that.data.parentid,
        page: that.data.page,
        pagback: that.data.pagback,
        server_key: server_key,
        hid: that.data.hid,
        week: week,
        zhic: zhic,
        dex1: dex1,
        city: city,
      },
      success: function (res) {
        console.log(res)
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: page,
          isLoading: !1
        })
      }
    })
  },
  onReachBottom: function () {
    var that = this;
    var biaoqian = that.data.biaoqian
    var page = that.data.page
    that.getAlldoclist(biaoqian);
  },
  //查询所有的
  getAlldoczhicheng() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.getzhichenglist',
      success: function (res) {
        console.log(res)
        that.setData({
          section2: res.data
        })
      }
    })
  }
})